package com.xinya.navigationapplication.activity

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import com.xinya.navigationapplication.R
import kotlinx.android.synthetic.main.activity_demo.*

/**
 *
 * @ClassName:      DemoActivity$
 * @Description:    java类作用描述
 * @Author:         xinya
 * @CreateDate:     2021/1/28$ 14:42$
 * @UpdateRemark:   更新内容
 * @Version:        1.0
 */
class DemoActivity : AppCompatActivity() {

    companion object {
        private const val TAG = "DemoActivity"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_demo)

        val navHostFragment =
            supportFragmentManager.findFragmentById(R.id.navFragmentContainerView) as NavHostFragment
        navBottomView.setupWithNavController(navHostFragment.navController)

        initView()

    }

    private fun initView() {
        // 程序选择
//        navBottomView.menu.getItem(2).isChecked = true
        // 设置点击监听
        navBottomView.setOnNavigationItemSelectedListener {
            when (it.itemId) {
                R.id.action_news -> Log.d(TAG, "initView: 新闻被点击了")
                R.id.action_me -> Log.d(TAG, "initView: 我的被点击了")
                else -> Log.d(TAG, "initView: 其他")
            }
            true
        }
    }
}